//
//  testTest.swift
//  Speek
//
//  Created by MikeHo on 2023/4/25.
//

import SwiftUI
import Combine


import Foundation

//struct Bill {
//    var time: String
//    var event: String
//    var amount: Double
//    var type: String
//    var tag: String
//    
//    
//    
////    
////    init(time: String, event: String, amount: Double, type: String, tag : String) {
////        self.time = time
////        self.event = event
////        self.amount = amount
////        self.type = type
////        self.tag = tag
////    }
//}




struct testTest: View {
    @State private var inputText = ""
    @State private var outputText = ""
    // Environment Properties
    @Environment(\.managedObjectContext) private var context
    
    private let apiKey = "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" // 替换为您的API密钥
    

    var body: some View {
        VStack {
            TextField("请输入文本", text: $inputText)
                .padding()
                .textFieldStyle(RoundedBorderTextFieldStyle())
                .keyboardType(.asciiCapable) // 设置为默认键盘类型

            Button("发送") {
//                var bill = chatWithGPT(inputText: inputText) ?? Bill(time: "", event: "", amount: 0.0, type: "", tag: "")
//                print(bill.time)
//                print(bill.event)
//                print(bill.amount)
//                print(bill.type)
//                print(bill.tag)
//                print(outputText)
                chatWithGPT(inputText: inputText, context: context) { Bool in
                    
                }
            }
            .padding()

//            Text(outputText)
//                .padding()
        }
        .padding()
//        .onReceive(Just(outputText)) { text in
//            print(text)
//
//        }
    }


}

struct testTest_Previews: PreviewProvider {
    static var previews: some View {
        testTest()
    }
}
